<template>
  <z-form-item
    :label-col="{ style: { width: '120px', paddingRight: '6px' } }"
    :required="formForm?.required === '1'"
    :prop="basicForm.field"
    :label="formForm?.headText && formForm.personal == '1' ? formForm?.headText : basicForm?.titleName || '日期框'"
    class="z-form-item"
  >
    <z-date-picker
      v-model:value="model[basicForm.field]"
      :value="formForm.value"
      :disabled="formForm?.disabled === '1'"
      :placeholder="formForm?.placeHolder"
      :picker="formForm?.targetType"
      :value-format="formForm?.typeFormat == '1' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'"
      :format="formForm?.typeFormat == '1' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'"
      :min="formForm?.min"
      :max="formForm?.max"
      :show-time="formForm?.typeFormat == '2'"
    />
    <!-- v-bind="getAttr()" -->
  </z-form-item>
</template>
<script>
import { defineComponent, toRef, computed } from 'vue'
import dayjs from 'dayjs'
export default defineComponent({
  name: 'DateItem',
  props: {
    formProperty: {
      type: Object,
      default: undefined
    },
    basicProperty: {
      type: Object,
      default: undefined
    },
    formModel: {
      type: Object,
      default: undefined
    }
  },
  setup(props) {
    const basicForm = toRef(props, 'basicProperty')
    const formForm = toRef(props, 'formProperty')
    const model = computed(() => props.formModel ? props.formModel : {})

    // 控件大小值
    const getMax = (date) => dayjs(date).hour(23).minute(59).second(59).format('YYYY-MM-DD HH:mm:ss')
    const getMin = (date) => dayjs(date).hour(0).minute(0).second(0).format('YYYY-MM-DD HH:mm:ss')
    const getAttr = () => {
      const attr = {}
      if (formForm.value.max) {
        attr['max'] = getMax(formForm.value.max)
      }
      if (formForm.value.min) {
        attr['min'] = getMin(formForm.value.min)
      }
      return attr
    }
    return {
      basicForm,
      formForm,
      getAttr,
      model
    }
  }
})

</script>
<style lang="less" scoped>
.z-form-item{
  flex: 1;
}
</style>
